﻿/*
* @author Mikko Miettinen
*/
// Manually constructed Array of all 18 possible card positions...
//only works for scaled cards
var cardLocations =	new Array 
( 
	Vector3 (5.0 ,3,-3.1), Vector3(5.0 -2 ,3,-3.1), Vector3(5.0 -4 ,3,-3.1), Vector3(5.0 -6 ,3,-3.1),Vector3(5.0 -8 ,3,-3.1), Vector3(5.0 -10 ,3,-3.1),
	Vector3 (5.0 ,3,-5.9), Vector3(5.0 -2 ,3,-5.9), Vector3(5.0 -4 ,3,-5.9), Vector3(5.0 -6 ,3,-5.9),Vector3(5.0 -8 ,3,-5.9), Vector3(5.0 -10 ,3,-5.9),
	Vector3 (5.0 ,3,-8.7), Vector3(5.0 -2 ,3,-8.7), Vector3(5.0 -4 ,3,-8.7), Vector3(5.0 -6 ,3,-8.7),Vector3(5.0 -8 ,3,-8.7), Vector3(5.0 -10 ,3,-8.7)
	
	);
//array for all different cards				
var allCards : GameObject;
var parentObject : GameObject;
//for storing used card location
var usedCardLocation;
//array to store unique cards
var uniqueCard = new Array ();
				
				
function Start () 
{	
	// Find all Game Objects that are Tagged "Cards"...
	// and that are supplied to allCards on editor side
	uniqueCard = allCards.FindGameObjectsWithTag ("Cards");
	
	// Randomize the order of the Cards...
	for ( var c=0; c <= uniqueCard.length-1; c++)
	{
		var thisCard = Random.Range (c, uniqueCard.length);
		
		usedCardLocation = uniqueCard [c];
		
		uniqueCard [c] = uniqueCard [thisCard];
		
		uniqueCard [thisCard] = usedCardLocation;
	}
	
	// Randomize the order of the Card Locations...
	
	for ( var i=0; i <= cardLocations.length-1; i++)
	{
		var thisCardLocation = Random.Range (i, cardLocations.length);
		
		usedCardLocation = cardLocations [i];
		
		cardLocations [i] = cardLocations [thisCardLocation];
		
		cardLocations [thisCardLocation] = usedCardLocation;
		
		// Instantiate our Randomized Cards and parent them to empty Game Objects so the animations play in Local Space...
		// dunno if animations are valid consern on this since we use iTween on runtime and not normal animations
		var theCard : GameObject = Instantiate (uniqueCard [i/2], Vector3(0,0,0), Quaternion.identity);
		//we scale the cards to fit our screen
		theCard.transform.localScale = Vector3(0.1f,0,0.1f);
	
		var theParent : GameObject = Instantiate (parentObject, Vector3(0,0,0) , Quaternion.identity);
		
		theCard.transform.parent = theParent.transform;
		
		theParent.transform.position = cardLocations [i];
	}
	
	// Destroy the group of cards that we're using to generate the Card Locations...
	Destroy (allCards, 0.1);
}	